//tree 是一个层级不固定的树形结构，每个节点包含 key、count 和 children 属性。
//编写一段代码，递归计算每个节点的 count 值，count 值表示以该节点为根的子树中包含的节点总数（包含当前节点自身）。

function Tree(key) {
    this.key = key;
    this.count = 0;
    this.children = [];
}

function countNode(node){
    node.count = 1;
    for(let i = 0; i < node.children.length; i++){
        countNode(node.children[i]);
        node.count += node.children[i].count;
    }
    return node.count;
}
let tree = new Tree(1);
tree.children.push(new Tree(2));
tree.children.push(new Tree(3));
tree.children[0].children.push(new Tree(4));

console.log(countNode(tree))
